package cn.hdu.liang.proxy.invocation;

import cn.hdu.liang.proxy.Hello;
import cn.hdu.liang.proxy.HelloImpl;

import java.lang.reflect.Proxy;

public class InvoMain {

    public static void main(String[] args) {
        genProxy();
    }

    private static void genProxy() {
        DynamicProxy dynamicProxy = new DynamicProxy(new HelloImpl());
        Hello helloProxy = dynamicProxy.getProxy();
        helloProxy.say("Jack");
    }

    private static void dynamicProxy() {
        Hello hello = new HelloImpl();

        DynamicProxy dynamicProxy = new DynamicProxy(hello);

        Hello helloProxy = (Hello) Proxy.newProxyInstance(
                hello.getClass().getClassLoader(),
                hello.getClass().getInterfaces(),
                dynamicProxy
        );

        helloProxy.say("Jack");
    }
}
